﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Http;

using Microsoft.Practices.Unity;
using Microsoft.Owin.Hosting;

using ERPStore.Extensions;

using Owin;

using EventBrokR;

namespace ERPStore.Tasks
{
	public class PluginInit : ERPStore.Extensibility.PluginInit
	{
		public PluginInit()
		{
			Container = GlobalConfiguration.Configuration.DependencyResolver.GetContainer();
		}

		protected Microsoft.Practices.Unity.IUnityContainer Container { get; set; }

		public override void AddServices()
		{
			var settings = new Models.Settings();
			settings.BindFromConfiguration(Configuration.ConfigurationSettings.AppSettings);
			Container.RegisterInstance(settings, new ContainerControlledLifetimeManager());

			Container.RegisterType<ERPStore.Services.IScheduledTaskService, Services.ScheduledTaskService>(new ContainerControlledLifetimeManager());
			Container.RegisterType<ERPStore.Services.IPersistentConnection, Services.TasksConnection>("TaskConnection");

			var eb = Container.Resolve<EventBrokR.IPublisher>();
			eb.Container.Register<EventConsumers.EndApplicationRequestedEventConsumer>();
			eb.Container.Register<EventConsumers.ApplicationStartedEventConsumer>();
		}

		public override void Load()
		{
		}

	}
}
